﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace la.P2KServer.XAML_UI
{
    /// <summary>
    /// 
    /// </summary>
    public partial class P2KServerTextbox : P2KServerBase
    {
        public static DependencyProperty SourceProperty;

        public string Source                                            
        {
            set { SetValue(SourceProperty, value); }
            get { return (string)GetValue(SourceProperty); }
        }        
        public static string GetSource(UIElement element)               
        {
            if (element == null) throw new ArgumentException("");
            return (string)element.GetValue(P2KServerTextbox.SourceProperty);
        }
        public static void SetSource(UIElement element, string value)   
        {
            if (element == null) throw new ArgumentException("");
            element.SetValue(P2KServerTextbox.SourceProperty, value);
        }

        static P2KServerTextbox()
        {
            FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata("", propertyChangedCallback);
            SourceProperty = DependencyProperty.RegisterAttached("Source", typeof(string), typeof(FrameworkElement), metadata);
        }

        public P2KServerTextbox()
        {
            InitializeComponent();            
        }

        public static void propertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if ((e.NewValue.ToString().Split('.')).Length == 3)
            {
                RoutedEventArgs routedEvent = new RoutedEventArgs(P2KServerBase.ResiveDataEvent, d);
                ((P2KServerTextbox)d).RaiseEvent(routedEvent);
            }            
        }
    }
}
